package com.moody.hibernate.dao;

import java.util.List;
import org.hibernate.LockMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.moody.hibernate.domain.OrgInfo;

/**
 * A data access object (DAO) providing persistence and search support for
 * OrgInfo entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see com.moody.hibernate.domain.OrgInfo
 * @author MyEclipse Persistence Tools
 */

public class OrgInfoDAO extends HibernateDaoSupport {
	private static final Logger log = LoggerFactory.getLogger(OrgInfoDAO.class);
	// property constants
	public static final String ORGNAME = "orgname";
	public static final String ORGLEVEL = "orglevel";
	public static final String BANKID = "bankid";
	public static final String AREACODE = "areacode";
	public static final String ORG_CODE = "orgCode";
	public static final String SETUPDATE = "setupdate";
	public static final String ORGADD = "orgadd";
	public static final String ORGTEL = "orgtel";
	public static final String INPUT_USER_ID = "inputUserId";
	public static final String INPUT_ORG_ID = "inputOrgId";
	public static final String INPUT_DATE = "inputDate";
	public static final String UPDATE_USER_ID = "updateUserId";
	public static final String UPDATE_ORG_ID = "updateOrgId";
	public static final String UPDATE_DATE = "updateDate";
	public static final String REMARK = "remark";

	protected void initDao() {
		// do nothing
	}

	public void save(OrgInfo transientInstance) {
		log.debug("saving OrgInfo instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(OrgInfo persistentInstance) {
		log.debug("deleting OrgInfo instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.info("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public OrgInfo findById(java.lang.String id) {
		log.debug("getting OrgInfo instance with id: " + id);
		try {
			OrgInfo instance = (OrgInfo) getHibernateTemplate().get(
					"com.moody.hibernate.domain.OrgInfo", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(OrgInfo instance) {
		log.debug("finding OrgInfo instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding OrgInfo instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from OrgInfo as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByOrgname(Object orgname) {
		return findByProperty(ORGNAME, orgname);
	}

	public List findByOrglevel(Object orglevel) {
		return findByProperty(ORGLEVEL, orglevel);
	}

	public List findByBankid(Object bankid) {
		return findByProperty(BANKID, bankid);
	}

	public List findByAreacode(Object areacode) {
		return findByProperty(AREACODE, areacode);
	}

	public List findByOrgCode(Object orgCode) {
		return findByProperty(ORG_CODE, orgCode);
	}

	public List findBySetupdate(Object setupdate) {
		return findByProperty(SETUPDATE, setupdate);
	}

	public List findByOrgadd(Object orgadd) {
		return findByProperty(ORGADD, orgadd);
	}

	public List findByOrgtel(Object orgtel) {
		return findByProperty(ORGTEL, orgtel);
	}

	public List findByInputUserId(Object inputUserId) {
		return findByProperty(INPUT_USER_ID, inputUserId);
	}

	public List findByInputOrgId(Object inputOrgId) {
		return findByProperty(INPUT_ORG_ID, inputOrgId);
	}

	public List findByInputDate(Object inputDate) {
		return findByProperty(INPUT_DATE, inputDate);
	}

	public List findByUpdateUserId(Object updateUserId) {
		return findByProperty(UPDATE_USER_ID, updateUserId);
	}

	public List findByUpdateOrgId(Object updateOrgId) {
		return findByProperty(UPDATE_ORG_ID, updateOrgId);
	}

	public List findByUpdateDate(Object updateDate) {
		return findByProperty(UPDATE_DATE, updateDate);
	}

	public List findByRemark(Object remark) {
		return findByProperty(REMARK, remark);
	}

	public List findAll() {
		log.debug("finding all OrgInfo instances");
		try {
			String queryString = "from OrgInfo";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public OrgInfo merge(OrgInfo detachedInstance) {
		log.debug("merging OrgInfo instance");
		try {
			OrgInfo result = (OrgInfo) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(OrgInfo instance) {
		log.debug("attaching dirty OrgInfo instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(OrgInfo instance) {
		log.debug("attaching clean OrgInfo instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static OrgInfoDAO getFromApplicationContext(ApplicationContext ctx) {
		return (OrgInfoDAO) ctx.getBean("OrgInfoDAO");
	}

	public void update(OrgInfo org) {
		log.debug("attaching clean OrgInfo instance");
		try {
			getHibernateTemplate().update(org);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}